package cn.edu.tsinghua.card;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

/**
 * 常见复姓类
 */
public enum CompositeSurnames {
	INSTANCE;
	
	private Set<String> surnames;
	
	protected void init() {
		surnames = new HashSet<>();
		try(BufferedReader reader = new BufferedReader(new InputStreamReader(
				CompositeSurnames.class.getResourceAsStream("/composite-surnames.txt"), StandardCharsets.UTF_8))) {
			String line = reader.readLine();
			while(line != null) {
				surnames.add(line.strip());
				line = reader.readLine();
			}			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Set<String> getSurnames() {
		if(INSTANCE.surnames == null) {
			INSTANCE.init();
		}
		return INSTANCE.surnames;
	}
}
